import base64
import io

from PIL import Image

def base64_to_ico(base64_string, output_file):
    try:
        # 解码Base64字符串
        decoded_data = base64.b64decode(base64_string)

        # 创建Image对象
        img = Image.open(io.BytesIO(decoded_data))

        # 保存为.ico文件
        img.save(output_file, format="ICO", sizes=[(32, 32), (64, 64)])  # 选择需要的图像尺寸

        print("转换成功！已将Base64字符串保存为.ico文件：", output_file)
    except Exception as e:
        print("转换失败:", e)


if __name__ == "__main__":
    # 输入Base64字符串和输出文件名
    # base64_data = input("请输入Base64字符串: ")
    base64_data = "iVBORw0KGgoAAAANSUhEUgAAAEgAAABJCAYAAACesWDiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA1MSURBVHgB7VwJdFXVFT3nvT8kBAiDiighPyRA2yguCCiBgFksIQyuEFCxVZfQiuJUCaBCVTQIRYoyV2kdCqJtGRSCYJAAC0QIgyIFi4okkJ9AylAwATP84d3T8z7gSv7/9/2f8aVrsdeC99695w5v3/vOOffc+4PQTBAbuzlOIN6pIER5BB0scablQTMAgsnIyiLlvfe3vA4EmfyoXE1HpP02VbsnP3/4STARphPU2ZG7kAAmBstDoKMKeFMLC0ecBpOggImIi9t2u4wcHQTYXUPrk2AiTCVII21EGGLDwESYShCxQg4tBDeBiTCXICBnKBlE+A5MhKkECQWy+eIykiEFPgQTYSpBJQVpxYjiMb71SERWFhcMWQ4mwlSCdBSdGLpCUdWhfLuT/2ngM16Qzw7j0ze0b/cwXEN1ZFkSEnLs0IzQ5I6i7jlvLYVBrH/uAAEW9oMO7VmI2cFku6yvfJBQHc+30SjEfrtmn/HdPfgfaEI0KUEDMqkjf0Mfc6vJNTII/o0E9+5ehEevJsVlu15guT/WlKNil2LvVZKO/4UmQpPqIIHwZgA5OhBuIRXeTs0ii/4Yv/bSDajAjEA5jLFR1RvQhGgygpIn08P8OY2SChAMdF+ER/VbAXgbEViCiSEoY7t8St2gidAkn1jSFLouQsB+JiguhGixjaDH8UHum1X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bCe4QSJs0doEsDj78QhrZsVw5B8P+NrUvqCVQ8Zy+1unwX2qVhn071TwsopFishyBURYKubNPSImjeKDzTq8wXjmWd9ENocdth/5QAgoQQb/OlEuQoBbT5Dk4WF6at5Bn3OjRTsFM6C9aM8Z2ltqm+zU2j80gVVgWW+icGNfNx6z0DAUUu0+4X+8EzvI66X/dlqqd2is0dzovPCezWsM9EJv9aRz9cTgUK4WKOd39aPaf/ZOrLM0l/r5pLIoRSDuU8snshrg2oTdZMVw5JeDXlcX7pOwiF4Aa3eVH83ZkeeQL+j5HKvpBbgfGgbzpcdlS3CwGr9i5EU3/6eQ3XcA3X0OyRMCzHnpq6vVY7LY2NJv1JZjAkJX1lPXPhxwlIIpO704V3MIiDK7sQtVeLjg/bBibDdIJiHLn/5EuwaKSHN03H6z8bBxNhKkExjm3jeCfI4PgKuW1qREJBwZ3FYBLM/dsdpIU4u4M2j3BngIkwlSBenoT8gQkvXWLBRJj7pykodLiESQx7i6YxYPLf7lA2hZIQgnLARJhKUBW63tL/TpksnxRYdLIwbR+YCFMJOlc44rRm0e5iPbPfL0uwfZ1/8njeZDAZpvtBVxEbuzUZFNGLSPkJSdvpdKY1i7DK/wBV+dL8uJdVWQAAAABJRU5ErkJggg=="
    # output_file_name = input("请输入输出文件名: ")
    output_file_name = "lyzw2.ico"

    # 调用函数将Base64转换为.ico文件
    base64_to_ico(base64_data, output_file_name)
